<?php

use think\facade\Route;
use think\facade\Request;

$version = Request::header('version', 'v2');#接口版本
Route::group('', function () use ($version) {
    // 登录
    Route::group('site', function () use ($version) {
        Route::post('login', "backend/{$version}.Site/login");
        Route::post('register', "backend/{$version}.Site/register");
    });

    // 后台用户管理
    Route::group('backendMember', function () use ($version) {
        Route::get('read', "backend/{$version}.BackendMember/read");
        Route::get('create', "backend/{$version}.BackendMember/create");
        Route::post('save', "backend/{$version}.BackendMember/save");
        Route::post('update', "backend/{$version}.BackendMember/update");
        Route::get('edit', "backend/{$version}.BackendMember/edit");
        Route::delete('delete', "backend/{$version}.BackendMember/delete");
        Route::get(':id', "backend/{$version}.BackendMember/index");
        //  获取后台角色信息
        Route::get('get-role', "backend/{$version}.BackendMember/getrole");
        Route::get('member-info', "backend/{$version}.BackendMember/memberInfo");
        Route::get('login-out', "backend/{$version}.BackendMember/loginOut");
        //  清除缓存
        Route::get('clear-cache', "backend/{$version}.BackendMember/clearcache");
        //获取管理员数量
        Route::get('membercount', "backend/{$version}.BackendMember/membercount");
    })->middleware('checkLogin');

    // 后台教师管理
    Route::group('teacher', function () use ($version) {
        Route::post('read', "backend/{$version}.Teacher/read");
        Route::post('save', "backend/{$version}.Teacher/save");
    });
//        ->middleware('checkLogin');

    // 前台用户注册
    Route::group('apiSite', function () use ($version) {
        Route::post('register', "backend/{$version}.ApiSite/register");
    });

    // 前台用户管理
    Route::group('apiMember', function () use ($version) {
        Route::get('index', "backend/{$version}.ApiMember/index");
        Route::post('save', "backend/{$version}.ApiMember/save");
        Route::get('edit', "backend/{$version}.ApiMember/edit");
        Route::post('update', "backend/{$version}.ApiMember/update");
        Route::delete('delete', "backend/{$version}.ApiMember/delete");
        //  清除缓存
        Route::get('clear-cache', "backend/{$version}.ApiMember/clearcache");
        //获取管理员数量
        Route::get('membercount', "backend/{$version}.ApiMember/membercount");
    })->middleware('checkLogin');

    // 会员管理
    Route::group('member', function () use ($version) {
        Route::get('index', "backend/{$version}.Member/index");
        Route::post('create', "backend/{$version}.Member/create");
        Route::put('update', "backend/{$version}.Member/update");
        Route::delete('delete', "backend/{$version}.Member/delete");
    })->middleware('checkLogin');

    //节点管理
    Route::group('permission', function () use ($version) {
        Route::get('index', "backend/{$version}.BackendPermission/index");
        Route::get('create', "backend/{$version}.BackendPermission/create");
        Route::post('save', "backend/{$version}.BackendPermission/save");
        Route::post('update', "backend/{$version}.BackendPermission/update");
        Route::get('edit', "backend/{$version}.BackendPermission/edit");
        Route::delete('delete', "backend/{$version}.BackendPermission/delete");
    })->middleware('checkLogin');

    //角色管理
    Route::group('role', function () use ($version) {
        Route::get('index', "backend/{$version}.BackendRole/index");
        Route::post('save', "backend/{$version}.BackendRole/save");
        Route::post('update', "backend/{$version}.BackendRole/update");
        Route::get('edit', "backend/{$version}.BackendRole/edit");
        Route::delete('delete', "backend/{$version}.BackendRole/delete");
    })->middleware('checkLogin');

    //角色权限
    Route::group('rolePermission', function () use ($version) {
        Route::get('create', "backend/{$version}.BackendRolePermission/create");
        Route::get('index', "backend/{$version}.BackendRolePermission/index");
        Route::post('save', "backend/{$version}.BackendRolePermission/save");
        Route::post('update', "backend/{$version}.BackendRolePermission/update");
        Route::get('edit', "backend/{$version}.BackendRolePermission/edit");
        Route::delete('delete', "backend/{$version}.BackendRolePermission/delete");
    })->middleware('checkLogin');

    //图片上传
    Route::group('upload', function () use ($version) {
        Route::post('upload', "backend/{$version}.upload/upload");
    });

    //音频上传
    Route::group('music', function () use ($version) {
        Route::post('music', "backend/{$version}.music/music");
    });

    //datum_cate课本名称
    Route::group('textbook', function () use ($version) {
        Route::post('index', "backend/{$version}.TextBook/index");
    });

    //年级管理
    Route::group('Grade', function () use ($version) {
        Route::get('index', "backend/{$version}.Grade/index");
        Route::post('create', "backend/{$version}.Grade/create");
        Route::post('update', "backend/{$version}.Grade/update");
        Route::delete('delete', "backend/{$version}.Grade/delete");
    })->middleware('checkLogin');

    //班级管理
    Route::group('room', function () use ($version) {
        Route::get('index', "backend/{$version}.Room/index");
        Route::post('create', "backend/{$version}.Room/create");
        Route::post('update', "backend/{$version}.Room/update");
        Route::delete('delete', "backend/{$version}.Room/delete");
    })->middleware('checkLogin');

    //错题管理
    Route::group('Error', function () use ($version) {
        Route::get('index', "backend/{$version}.Error/index");
        Route::post('create', "backend/{$version}.Error/create");
        Route::post('update', "backend/{$version}.Error/update");
        Route::delete('delete', "backend/{$version}.Error/delete");
    })->middleware('checkLogin');

    //错题查看详情
    Route::group('errordetail', function () use ($version) {
        Route::get('index', "backend/{$version}.ErrorDetail/index");
    })->middleware('checkLogin');

    //资料库管理
    Route::group('Datum', function () use ($version) {
        Route::get('index', "backend/{$version}.Datum/index");
        Route::get('read', "backend/{$version}.Datum/read");
        Route::get('unit', "backend/{$version}.Datum/unit");
        Route::get('edit', "backend/{$version}.Datum/edit");
        Route::post('create', "backend/{$version}.Datum/create");
        Route::post('update', "backend/{$version}.Datum/update");
        //单删
        Route::delete('delete', "backend/{$version}.Datum/delete");
        //批量删除
        Route::delete('delAll', "backend/{$version}.Datum/delAll");
    })->middleware('checkLogin');

    //资料库导入
    Route::group('Datum', function () use ($version) {
        Route::post('importExcel', "backend/{$version}.Datum/importExcel");
    })->middleware('checkLogin');

    //题库管理
    Route::group('question', function () use ($version) {
        Route::get('index', "backend/{$version}.Question/index");
        Route::get('read', "backend/{$version}.Question/read");
        Route::post('create', "backend/{$version}.Question/create");
        Route::post('update', "backend/{$version}.Question/update");
        Route::delete('delete', "backend/{$version}.Question/delete");
        //题库导入
        Route::post('importExcel', "backend/{$version}.Question/importExcel");
    })->middleware('checkLogin');

    //课程分类管理
    Route::group('Course', function () use ($version) {
        Route::get('index', "backend/{$version}.Course/index");
        Route::post('create', "backend/{$version}.Course/create");
        Route::post('update', "backend/{$version}.Course/update");
        Route::delete('delete', "backend/{$version}.Course/delete");
    })->middleware('checkLogin');

    //记录学/做表管理
    Route::group('Record', function () use ($version) {
        Route::get('index', "backend/{$version}.Record/index");
        Route::post('create', "backend/{$version}.Record/create");
        Route::post('update', "backend/{$version}.Record/update");
        Route::delete('delete', "backend/{$version}.Record/delete");
        //进度
        Route::get('location', "backend/{$version}.Record/location");
        //教师
        Route::get('teacher', "backend/{$version}.Record/teacher");
    })->middleware('checkLogin');

    //学习中心--分类管理
    Route::group('datumCate', function () use ($version) {
        Route::get('index', "backend/{$version}.DatumCate/index");
        Route::get('read', "backend/{$version}.DatumCate/read");
        Route::post('create', "backend/{$version}.DatumCate/create");
        Route::post('update', "backend/{$version}.DatumCate/update");
        Route::delete('delete', "backend/{$version}.DatumCate/delete");
    })->middleware('checkLogin');

    //试卷名称管理
    Route::group('paper', function () use ($version) {
        Route::get('index', "backend/{$version}.Paper/index");
        Route::get('before', "backend/{$version}.Paper/before");
        Route::get('edit', "backend/{$version}.Paper/edit");
        Route::post('create', "backend/{$version}.Paper/create");
        Route::post('update', "backend/{$version}.Paper/update");
        Route::delete('delete', "backend/{$version}.Paper/delete");
    })->middleware('checkLogin');

    //单元管理
    Route::group('Unit', function () use ($version) {
        Route::get('index', "backend/{$version}.Unit/index");
        Route::post('create', "backend/{$version}.Unit/create");
        Route::post('update', "backend/{$version}.Unit/update");
        Route::delete('delete', "backend/{$version}.Unit/delete");
        Route::get('unit', "backend/{$version}.Unit/unit");
    })->middleware('checkLogin');

})->allowCrossDomain([
    'Access-Control-Allow-Origin' => '*',
    'Access-Control-Allow-Methods' => 'GET,POST,PUT,DELETE',
    'Access-Control-Allow-Headers' => 'content-type,token,version',
    'Access-Control-Allow-Credentials' => 'true'
]);